<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>科室管理</title>
    <link rel="stylesheet" href="../assets/bootstrap.min.css">
</head>

<body>
<!-- 弹出框 -->
<div class="modal fade" id="addRolePop" tabindex="-1" aria-labelledby="addRolePopLa" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="addRolePopLa">添加科室</h5>
                <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form class="d-grid gap-3" id="addRoleForm">
                    <input type="hidden" id="departmentId">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="departmentName">科室名称</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="departmentName" type="text" autocomplete="off"
                                   placeholder="科室名称">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="departmentInfo">科室简介</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="departmentInfo" type="text" autocomplete="off"
                                   placeholder="科室简介">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label" for="departmentAddress">科室地址</label>
                        <div class="col-sm-8">
                            <input class="form-control" id="departmentAddress" type="text" autocomplete="off"
                                   placeholder="科室地址">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button class="btn btn-secondary" data-bs-dismiss="modal" type="button">关闭</button>
                <button class="btn btn-primary" data-bs-dismiss="modal" type="button" id="submitForm">确认提交</button>
            </div>
        </div>
    </div>
</div>
<!-- 搜索与添加与批量删除 -->
<nav class="navbar bg-light sticky-top">
    <div class="container-fluid">
        <form class="d-flex" role="search" onsubmit="return false">
            <input class="form-control me-2" type="search" placeholder="科室名字" aria-label="Search" id="searchInput">
            <button class="btn btn-outline-success" type="submit" onclick="sss.getAll()">Search</button>
        </form>
        <div class="d-flex flex-row-reverse bd-highlight">
            <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#addRolePop"
                    onclick="sss.addTit()">添加科室
            </button>
        </div>
    </div>
</nav>
<!-- 表格 -->
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th>科室名</th>
        <th>简介</th>
        <th>地址</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tb-main">
    </tbody>
</table>
</body>
<script src="../assets/bootstrap.bundle.min.js"></script>
<script src="../assets/axios.js"></script>
<script src="z-myJS.js"></script>
<script type="text/javascript">
    const sss = new MixRole("department", "科室")
    window.onload = function () {
        sss.getAll();
    }// 向表格类动态添加数据
    function getDataRow(h) {
        const row = document.createElement('tr'); //创建行
        const {departmentId, departmentName, departmentInfo, departmentAddress} = h
        // 添加其他列
        row.appendChild(sss.cell(departmentName))
        row.appendChild(sss.cell(departmentInfo))
        row.appendChild(sss.cell(departmentAddress))
        //删除与修改按钮
        row.appendChild(sss.opCell(departmentId, h));
        return row;
    }//表单数据转json
    function formToJson() {
        return sss.getVal(["departmentId", "departmentName", "departmentInfo", "departmentAddress"])
    }//json数据转表单
    function jsonToForm(h) {
        sss.setVal(["departmentId", "departmentName", "departmentInfo", "departmentAddress"], h)
    }
</script>

</html>